package hms.rewards;

import java.sql.*;
import java.util.Arrays;
import java.util.Iterator;

import hms.database.*;

/*This class controls all interactions with 
 * Reward_Point_History table in DB
 * 
 * @author Edgar Onukwugha*/

public class RewardPointHistory extends DBRowObject{

	private int reward_account_ID;
	private int points_earned;
	private int points_spent;
	private Date reward_use;
	
	public RewardPointHistory(){
		super();
		reward_account_ID = -1;
		points_earned = 0;
		points_spent = 0;
		reward_use = null;
	}
	
	public RewardPointHistory(int point_history_ID){
		super(point_history_ID);
	}
	
	/////////////////////////////////////////////////
	/////               SETTERS                //////
	/////////////////////////////////////////////////
		
	public void setRewardAccountID(int i){
		reward_account_ID = i;
		markAsChanged();
	}
	
	public void setPointsEarned(int i){
		points_earned = i;
		markAsChanged();
	}
	
	public void setPointsSpent(int i){		
		points_spent = i;
		markAsChanged();
	}
	
	public void setRewardUse(Date i){
		reward_use = i;
		markAsChanged();
	}
	
	/////////////////////////////////////////////////
	/////               GETTERS                //////
	/////////////////////////////////////////////////
	
	public int getRewardAccountID(){
		return reward_account_ID;
	}
	
	public int getPointsEarned(){
		return points_earned;
	}
	
	public int getPointsSpent(){
		return points_spent;
	}
	
	public Date getRewardUse(){
		return reward_use;
	}
	
	@Override
	protected String[] getFieldNames() {
		String[] output = new String[4];
		output[0] = "REWARD_ACCOUNT_ID";
		output[1] = "POINTS_EARNED";
		output[2] = "POINTS_SPENT";
		output[3] = "REWARD_USE";
		
		return output;
	}

	@Override
	protected void loadPreparedStatement(PreparedStatement stmt)
			throws SQLException {
		stmt.setInt(1, reward_account_ID);
		stmt.setInt(2, points_earned);
		stmt.setInt(3, points_spent);
		stmt.setDate(4, reward_use);
		
	}

	@Override
	protected String getUniqueIdentifierFieldName() {
		// TODO Auto-generated method stub
		return "POINT_HISTORY_ID";
	}

	@Override
	protected String getTableName() {
		// TODO Auto-generated method stub
		return "REWARD_POINT_HISTORY";
	}

	@Override
	protected void loadFromDatabase(ResultSet rs) throws SQLException {
		Iterator<String> i = Arrays.asList(getFieldNames()).iterator();
		reward_account_ID = rs.getInt(i.next());
		points_earned = rs.getInt(i.next());
		points_spent = rs.getInt(i.next());
		reward_use = rs.getDate(i.next());
	}

	@Override
	protected boolean allowDuplicateRows() {
		// TODO Auto-generated method stub
		return false;
	}

}
